<template>
	<view class="order">
		<uni-nav-bar left-icon="arrowleft" right-icon="search" title="已取消订单" @clickLeft="back" @clickRight="find" :fixed="true" class="top"></uni-nav-bar>
		<view class="uni-flex">
			商品总数：
			<text>{{total}}个</text>
		</view>
		<view class="list">
			<view class="li"   v-for="(item,index) in dataList" :key="index" >
				<view class="shop" @click="go_detalis(item.id)">
					<image :src="item.image" :lazy-load = "true" mode="aspectFill"/>			
					<view class="msg">
						<view class="order black">订单号：{{item.orderSn}}</view>
						<view class="order black">货号：{{item.goodsSn}}</view>
						<view class="time gray ">下单时间：{{item.createdTime}}</view>
						<view class="sizr gray ">操作时间：{{item.operationTime}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="pagination">
			<view class="left" :class="{ forbid: paging.page == 1 }" @click="prev">
				<uni-icons type="arrowleft" size="20" color="#fff" class="icons" />
				上一页
			</view>
			<view class="center">{{ paging.page }}/{{ paging.total }}</view>
			<view class="right" :class="{ forbid: paging.page == paging.total }" @click="next">
				下一页
				<uni-icons type="arrowright" size="20" color="#fff" class="icons" />
			</view>
		</view>
		<view class="go-top" v-show="is_go_top" @click="backTop"><image src="/static/img/go_top.png" /></view>
	</view>
</template>

<script>
import { uniNavBar, uniIcons } from '@dcloudio/uni-ui';
import shipments from '../../servers/shipments/shipments.js';
export default {
	components: { uniNavBar, uniIcons },
	data() {
		return {
			active: 0,
			dataList: [1],
			is_go_top:true,
			paging: {
				page: 1,
				total: 100
			},
			total:''
		};
	},
	onPageScroll: function(e) {
		//nvue暂不支持滚动监听，可用bindingx代替
		if (e.scrollTop > 200) {
			this.is_go_top = true;
		} else {
			this.is_go_top = false;
		}
	},
	mounted() {		
		this.getData();
	},
	methods: {
		getData() {
			var obj = {orderStatus: 2, currentPage: this.paging.page, pageSize: 10};
			shipments.initData(obj)
				.then(res => {
					console.log(res.data.records);
					this.total=res.data.total;
					this.paging.total = Math.ceil(res.data.total / res.data.size);
					this.dataList = [];
					this.dataList = res.data.records.map(v => {
						v.image = this.imgCDNUrl + v.productImg;
						return v;
					});
				})
				.catch(err => {
					console.log(new Error('请检查网络后重试'));
				});
		},
		go_detalis(e){
			var obj={id:e,frontOrderStatus:2}
			uni.setStorage({
			    key: 'shipmentsalterdetails',
			    data: obj,
			    success: function () {
			        uni.navigateTo({
			            url: '/pages/shipments/alterdetails'
			        });
			    }
			});
		},
		back() {
			uni.navigateBack({
				delta: 1
			});
		},
		cut(e) {
			this.active = e;
		},
		find() {
			uni.navigateTo({
				url: './find'
			});
		},
		next() {
			if (this.paging.page < this.paging.total) {
				this.paging.page += 1;
			}
		},
		prev() {
			if (this.paging.page > 1) {
				this.paging.page -= 1;
			}
		},
		// 计算距离顶部的高度，均分10等分，
		backTop() {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 200
			});
		}
	}
};
</script>

<style lang="less" scoped>
page {
	background: #ffffff;
}
.order {
	.uni-flex {
		position: fixed;
		z-index: 1;
		top: 44px;
		width: 100%;
		background: #fff;
		box-shadow: 5rpx 0px 20rpx #c5c5c5;
		text-align: center;
		color: #f70225;
		font-size: 28rpx;
		line-height: 89rpx;
		text {
			font-size: 32rpx;
		}
	}
	.list {
		border-top: 26rpx solid #f6f6f6;
		padding: 89rpx 20rpx 50rpx;
		.li {
			position: relative;
			padding: 50rpx 20rpx;
			margin: 38rpx 0;
			background: #fff;
			border-radius: 10rpx;
			box-shadow: 5rpx 0px 20rpx #c5c5c5;
			.shop {
				position: relative;
				display: flex;
				flex-direction: row;
				image {
					width: 220rpx;
					height: 220rpx;
					border-radius: 10rpx;
				}
				.msg {
					width: 431rpx;
					margin-left: 37rpx;
					line-height: 46rpx;
					.order {
						font-size: 28rpx;
					}
					.gray {
						color: #999999;
						font-size: 26rpx;
						line-height: 42rpx;
					}
				}
			}
		}
	}
}
</style>
